package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dto.ProductRecommendDTO;
import com.sc.nft.entity.vo.mall.RecommendActivityPageVO;
import com.sc.nft.enums.ProductTypeEnum;
import com.sc.nft.enums.task.ActivityTypeEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.MallRecommend;
import com.sc.nft.mapper.MallRecommendMapper;
import  com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 推荐商品表(sc_mall_recommend)数据DAO
 *
 * @author zxy
 * @since 2023-05-15 15:26:29
 * @description 活动推荐表
 */
@Slf4j
@Repository
public class MallRecommendDao extends ServiceImpl<MallRecommendMapper, MallRecommend> {


    public IPage<ProductRecommendDTO> getProductRecommend(ActivityTypeEnum activityType, ProductTypeEnum type, Boolean status, Long daoId, String name, Page page) {
        return baseMapper.getProductRecommend(page,activityType!=null?activityType.getCode():null, type!=null?type.getCode():null, status, daoId, name);
    }

    public MallRecommend getRecommendByActivityId(Long activityId) {
        LambdaQueryWrapper<MallRecommend> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallRecommend::getActivityId,activityId);
        return getOne(wrapper);
    }

    public List<Long> getRecommendByActivityIds(List<Long> activityIds) {
        LambdaQueryWrapper<MallRecommend> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(MallRecommend::getActivityId);
        wrapper.in(MallRecommend::getActivityId, activityIds);
        return listObjs(wrapper, x->(Long) x);
    }

    public IPage<RecommendActivityPageVO> recommendPage(ActivityTypeEnum activityType, ProductTypeEnum type, String productName,Page page) {
        return baseMapper.recommendPage(page,activityType!=null?activityType.getCode():null, type!=null?type.getCode():null,productName);
    }

}